package com.hee.erp.modules.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.hee.erp.common.R;
import com.hee.erp.exception.BusinessException;
import com.hee.erp.modules.entity.Car;
import com.hee.erp.modules.entity.Wf2Right;
import com.hee.erp.modules.entity.WfMain;
import com.hee.erp.modules.service.IWf2RightService;
import com.hee.erp.modules.service.IWfMainService;
import com.hee.erp.vo.CarListParamsVo;
import com.hee.erp.vo.page.WorkflowPageParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/modules/workflow")
public class WorkflowController {

    @Autowired
    private IWfMainService wfMainService;

    @Autowired
    IWf2RightService wf2RightService;

    @PostMapping("/save")
    @ApiOperation(value = "保存流程")
    public R save(@RequestBody WfMain wlMain){
        wfMainService.saveDetail(wlMain);
        return R.success(wlMain);
    }

    @ApiOperation("delById")
    @GetMapping("/delById")
    public R<Boolean> delById(String id){
        wfMainService.removeById(id);
        return R.success(true);
    }

    @ApiOperation(value = "getById")
    @GetMapping("/getById")
    public R getById(String id){
        Object entity = wfMainService.getDetailById(id);
        return R.success(entity);
    }

    @PostMapping("/listByPage")
    @ApiOperation(value = "listByPage")
    public R<IPage> listByPage(@RequestBody WorkflowPageParams params){
        IPage page = wfMainService.listByPage(params);
        return R.success(page);
    }

    @GetMapping("/getIdByRouteName")
    @ApiOperation(value = "getIdByRouteName")
    public R getIdByRouteName(String routeName){
        Wf2Right wf2Right = wf2RightService.getByRouteName(routeName);
        if(wf2Right == null){
           throw new BusinessException("没有找到对应的审批流程");
        }
        return R.success(wf2Right.getWfMainId());
    }





}
